<!-- BeginDsi "dsi/head.html" -->
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Embedthis GoAhead 3.1.1 Documentation</title>
    <meta name="keywords" content="embedded web server, web server software, embedded HTTP, application web server, 
        embedded server, small web server, HTTP server, library web server, library HTTP, HTTP library" />
    <meta name="description" content="Embedthis Sofware provides commercial and open source embedded web servers for 
        devices and applications." />
	<meta name="robots" content="index,follow" />
	<link href="../../../doc.css" rel="stylesheet" type="text/css" />
	<link href="../../../print.css" rel="stylesheet" type="text/css" media="print"/>
    <!--[if IE]>
    <link href="../../../iehacks.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    <link href="http://www.google.com/cse/style/look/default.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-179169-5']);
        _gaq.push(['_trackPageview']);
        (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();
    </script>
</head>

<body>
    <div class="top">
        <a class="logo" href="http://embedthis.com/products/goahead/">&nbsp;</a>
        <div class="topRight">
            <div class="search">
                <div id="cse-search-form"></div>
                <div class="version">Embedthis GoAhead 3.1.1</div>
            </div>
        </div>
        <div class="crumbs">
            <a href="../../../index.html">Home</a>
<!-- EndDsi -->
             &gt; <a href="index.html">Users Guide</a> &gt; <b>GoActions</b>
        </div>
    </div>
    <div class="content">
        <div class="contentRight">
            <h1>Quick Nav</h1>
            <ul class="nav">
            </ul>
<!-- BeginDsi "dsi/usersGuideSeeAlso.html" -->
            <h1>See Also</h1>
            <ul class="nav">
                <li><a href="../../../guide/goahead/users/index.html">User Guide Overview</a></li>
                <li><a href="../../../guide/goahead/users/authentication.html">User Authorization</a></li>
                <li><a href="../../../guide/goahead/users/logFiles.html">Log Files</a></li>
                <li><a href="../../../guide/goahead/users/security.html">Security Considerations</a></li>
                <li><a href="../../../guide/goahead/users/ssl.html">SSL</a></li>
                <li><a href="../../../guide/goahead/users/man.html">Man Pages</a></li>
            </ul>
<!-- EndDsi -->
        </div>
        <div class="contentLeft">
            <h1>GoActions</h1>
            <p>The traditional Common Gateway Interface (CGI) is a slow technique for creating dynamic web pages
            because CGI processing results in the creation of a new process for every request. This is slow and cumbersome.
            GoAhead provides a high-performance replacement called GoActions&trade; that is a more suitable solution 
            for embedded systems that demand compact and efficient solutions.</p>
            <p>GoActions are "C" language functions that are directly bound to specific URIs. They respond to client
            requests without creating a new process for each request. By sharing the address space with GoAhead, GoActions
            can directly access the full request context. GoActions are serviced by the <i>action</i> handler.</p>
            <h2>Defining GoActions</h2>
            <p>GoActions are defined by the 
            <i><a href="../../../api/goahead.html#group___webs_1gabadb35ad9084ca79783d0a63437d4959">websDefineAction</a></i> API.
            For example:</p>
<pre>
static void buy(Webs *wp)
{
    websSetStatus(wp, 200);
    websWriteHeaders(wp, 0, 0);
    websWriteEndHeaders(wp);
    websWrite(wp, "Name %s", websGetVar(wp, "name", "")); 
    websWrite(wp,  "Age %s", websGetVar(wp, "age", ""));
    websDone(wp);
}
<b>websDefineAction("buy", buy);</b>
</pre>
            <h2>Calling GoActions</h2>
            <p>GoActions are bound to URIs that begin with <i>/action/</i>. 
            When a client requests a URI <i>/action/NAME</i>, the action handler is invoked which then
            looks for a GoAction by NAME. The function bound to NAME is then is invoked to service the request. For
            example:</p>
            <pre>
/action/buy?name=John&amp;item=candy           
</pre>
            <p>This will invoke the GoAction <i>buy</i> which will run the bound C function. The action handler will
            automatically decode the query string "name=John&amp;age=30" and define GoAhead variables called "name" and "age".</p>
            <p>The GoAction is responsible for writing the HTTP header and HTML document content back to the user's
            browser.</p>
        </div>
    </div>
<!-- BeginDsi "dsi/bottom.html" -->
	<div class="bottom">
		<p class="footnote"> 
            <a href="../../../product/copyright.html" >&copy; Embedthis Software LLC, 2003-2013.
            All rights reserved. Embedthis and Embedthis GoAhead are trademarks of Embedthis Software LLC.</a>
		</p>
	</div>
    <script src="http://www.google.com/jsapi" type="text/javascript"></script>
    <script type="text/javascript"> 
      google.load('search', '1', {language : 'en'});
      google.setOnLoadCallback(function() {
        var customSearchControl = new google.search.CustomSearchControl(
          '000262706376373952077:1hs0lhenihk');
        customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        var options = new google.search.DrawOptions();
        options.enableSearchboxOnly("http://embedthis.com/search.html");
        customSearchControl.draw('cse-search-form', options);
      }, true);
    </script>
</body>
</html>
